package cn.openea.perpartner.payment.web.points.controller;

import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.payment.web.points.dto.FreezeDto;
import cn.openea.perpartner.payment.web.points.entity.Freeze;
import cn.openea.perpartner.payment.web.points.service.IFreezeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Weird077
 * @description TODO
 * @date 2022-10-27 12:15
 */
@Api(tags = "积分冻结")
@RestController
@RequestMapping("/freeze")
public class FreezeController extends BaseController {
    @Resource
    private IFreezeService freezeService;
    @ApiOperation("冻结")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id"),
            @ApiImplicitParam(name = "authUserid", value = "被授权用户id"),
            @ApiImplicitParam(name = "points", value = "积分"),
            @ApiImplicitParam(name = "reason", value = "原因"),
            @ApiImplicitParam(name = "orderId", value = "订单编号"),
            @ApiImplicitParam(name = "sourceId", value = "文档id"),
            @ApiImplicitParam(name = "sceneId", value = "场景id")
    })
    @PostMapping("/freezePoints")
    public AjaxResult freezePoints(@RequestBody FreezeDto dto) {
        return freezeService.freeze(dto) ? AjaxResult.success() : AjaxResult.error();
    }
    @ApiOperation("冻结列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id"),
            @ApiImplicitParam(name = "authUserId", value = "积分使用人"),
            @ApiImplicitParam(name = "pageNum", value = "当前页数"),
            @ApiImplicitParam(name = "pageSize", value = "当前页显示数"),
            @ApiImplicitParam(name = "sceneId", value = "场景id")
    })
    @PostMapping("/freezeList")
    public TableDataInfo selectFreezeList(@RequestBody FreezeDto freezeDto) {
        startPage();
        freezeDto.setStatus("1");
        List<Freeze> list = freezeService.selectList(freezeDto);
        return getDataTable(list);
    }
    @ApiOperation("使用列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true),
            @ApiImplicitParam(name = "authUserId", value = "积分使用人"),
            @ApiImplicitParam(name = "sceneId", value = "场景id")
    })
    @PostMapping("/usedList")
    public TableDataInfo selectUsedList(@RequestBody FreezeDto freezeDto) {
        startPage();
        freezeDto.setStatus("0");
        List<Freeze> list = freezeService.selectList(freezeDto);
        return getDataTable(list);
    }

    @ApiOperation("办结")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "freezeOrderId", value = "冻结的订单编号", required = true),
            @ApiImplicitParam(name = "sourceId", value = "文档id"),

    })
    @PostMapping("/closure")
    public AjaxResult closure(@RequestBody FreezeDto freezeDto) {
        return freezeService.closure(freezeDto) ? AjaxResult.success() : AjaxResult.error();
    }
    @ApiOperation(value = "结算")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "被扣减积分用户id"),
            @ApiImplicitParam(name = "targetUserId", value = "拍档用户Id"),
            @ApiImplicitParam(name = "freezeOrderId", value = "冻结的订单编号"),
            @ApiImplicitParam(name = "orderId", value = "订单编号"),
            @ApiImplicitParam(name = "points", value = "积分"),
            @ApiImplicitParam(name = "reason", value = "原因"),
            @ApiImplicitParam(name = "sceneId", value = "场景id")
    })
    @PostMapping("/settlement")
    public AjaxResult settlement(@RequestBody FreezeDto freezeDto) {
        return freezeService.settlement(freezeDto) ? AjaxResult.success() : AjaxResult.error("结算失败，请确认积分是否充足！");
    }

}
